<?php
namespace Amis\other;

use Amis\Basics\AmisBasics;

class Audio extends AmisBasics
{
    public string $type = 'audio';

    public function className($className)
    {
        $this->className = $className;
        return $this;
    }

    public function inline(bool $inline = true)
    {
        $this->inline = $inline;
        return $this;
    }

    public function src(string $src)
    {
        $this->src = $src;
        return $this;
    }

    /**
     * 是否循环播放
     * @param bool $loop
     * @return $this
     */
    public function loop(bool $loop = false)
    {
        $this->loop = $loop;
        return $this;
    }

    /**
     * 是否自动播放
     * @param bool $autoPlay
     * @return $this
     */
    public function autoPlay(bool $autoPlay = false)
    {
        $this->autoPlay = $autoPlay;
        return $this;
    }

    /**
     * 可配置音频播放倍速如：[1.0, 1.5, 2.0]
     * @param array $rates
     * @return $this
     */
    public function rates(array $rates = [])
    {
        $this->rates = $rates;
        return $this;
    }

    /**
     * 内部模块定制化
     * ['rates', 'play', 'time', 'process', 'volume']
     * @param array $controls
     * @return $this
     */
    public function controls(array $controls = [])
    {
        if (in_array($controls, ['rates', 'play', 'time', 'process', 'volume']))
            $this->controls = $controls;
        return $this;
    }
}